﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        bindData();

    }

    private void bindData()
    {
        iData.DataAcess worker = new iData.DataAcess();
        string sql = @"select ROW_NUMBER() OVER(order by id) AS i,ISNULL(b.value,0) as tbltitle,a.name as tblname from (
select o.name,o.id from sysobjects AS o
where o.xtype='U') as a left join (
select m.value,m.major_id from sys.extended_properties AS m
where  m.minor_id=0 ) as b on a.id=b.major_id";
        var dset = worker.Execute(sql);

        rptTblList.DataSource = dset;
        rptTblList.DataBind();

    }


    private void setTableMemo(string tblname, string memo)
    {
        string sql = @"select m.value,o.name from sys.extended_properties AS m,sysobjects AS o 
where o.id = m.major_id and m.minor_id = 0 and o.xtype = 'U' and o.name = 'appDataPort'";
        sql = sql.Replace("appDataPort", tblname);
        iData.DataAcess worker = new iData.DataAcess();
        int rowsCount = worker.ExecuteNonQuery(sql);
        if (rowsCount > 0)
        {
            //delete memo
            sql = "EXEC sp_dropextendedproperty 'MS_Description','user',dbo,'table','appDataPort'";
            sql = sql.Replace("appDataPort", tblname);
            worker.ExecuteNonQuery(sql);
        }

        sql = "exec sp_addextendedproperty N'MS_Description',N'" + memo + " ',N'user',N'dbo',N'table',N'appDataPort', NULL, NULL";
        sql = sql.Replace("appDataPort", tblname);
        worker.ExecuteNonQuery(sql);

    }

}